#! /bin/bash
#hdfs_to_ods_db.sh 表名/all [日期]
#1、判断参数是否传入
if [ $# -lt 1 ]
then
	echo "必须传入表名/all...."
	exit
fi
#2、判断日期是否传入,传入用指定日期,没有传入用前一天日期
[ "$2" ] && datestr=$2 || datestr=$(date -d '-1 day' +%F)

function load_data(){
	#获取函数第一个参数
	#$*与$@的区别: 如果没有用双引号括起来,没有区别,如果用双引号括起来,$*是将所有参数当做一个整体,$@是将参数当成一个个单独的个体
	#"$@"
	#"$*"
	tableNames=$*
	sql="use gmall;"
	for table in $tableNames
	do
		#目录存在会返回0
		hdfs dfs -test -e /origin_data/gmall/db/${table:4}/$datestr
		#如果数据目录存在才会加载数据
		if [ $? -eq 0 ]
		then
			sql="$sql;load data inpath '/origin_data/gmall/db/${table:4}/$datestr' overwrite into table ${table} partition (dt='$datestr');"
		fi
	done
	/opt/module/hive/bin/hive -e "$sql"
}

case $1 in
    "ods_base_category_info_full")
        load_data "ods_base_category_info_full"
    ;;
    "ods_base_province_full")
        load_data "ods_base_province_full"
    ;;
    "ods_base_source_full")
        load_data "ods_base_source_full"
    ;;
    "ods_base_subject_info_full")
        load_data "ods_base_subject_info_full"
    ;;
    "ods_chapter_info_full")
        load_data "ods_chapter_info_full"
    ;;
    "ods_course_info_full")
        load_data "ods_course_info_full"
    ;;
    
    "ods_knowledge_point_full")
        load_data "ods_knowledge_point_full"
    ;;
	
    "ods_test_paper_full")
        load_data "ods_test_paper_full"
    ;;
	
    "ods_cart_info_full")
        load_data "ods_cart_info_full"
    ;;
    "ods_test_point_question_full")
        load_data "ods_test_point_question_full"
    ;;
    "ods_test_question_info_full")
        load_data "ods_test_question_info_full"
    ;;
    "ods_test_question_option_full")
        load_data "ods_test_question_option_full"
    ;;
    "ods_video_info_full")
        load_data "ods_video_info_full"
    ;;
  "ods_test_paper_question_full")
        load_data "ods_test_paper_question_full"
    ;;
   

    "ods_cart_info_inc")
        load_data "ods_cart_info_inc"
    ;;
    "ods_comment_info_inc")
        load_data "ods_comment_info_inc"
    ;;
    
    "ods_favor_info_inc")
        load_data "ods_favor_info_inc"
    ;;
    "ods_order_detail_inc")
        load_data "ods_order_detail_inc"
    ;;
    
    
    "ods_order_info_inc")
        load_data "ods_order_info_inc"
    ;;
    
    
    "ods_payment_info_inc")
        load_data "ods_payment_info_inc"
    ;;
    "ods_review_info_inc")
        load_data "ods_review_info_inc"
    ;;
	
    "ods_test_exam_inc")
        load_data "ods_test_exam_inc"
    ;;
	
    "ods_test_exam_question_inc")
        load_data "ods_test_exam_question_inc"
		
    ;;
	
	"ods_test_paper_question_inc")
        load_data "ods_test_paper_question_inc"
		
    ;;
	
	"ods_user_chapter_process_inc")
        load_data "ods_user_chapter_process_inc"
		
    ;;
	
    "ods_user_info_inc")
        load_data "ods_user_info_inc"
    ;;
	
	"ods_vip_change_detail_inc")
        load_data "ods_vip_change_detail_inc"
    ;;
    "all")
        load_data "ods_base_category_info_full" "ods_base_province_full" "ods_base_source_full" "ods_base_subject_info_full" "ods_chapter_info_full" "ods_course_info_full" "ods_knowledge_point_full" "ods_test_paper_full" "ods_cart_info_full" "ods_test_point_question_full" "ods_test_question_option_full" "ods_test_question_info_full" "ods_video_info_full" "ods_test_paper_question_full" "ods_cart_info_inc" "ods_comment_info_inc" "ods_coupon_use_inc" "ods_favor_info_inc" "ods_order_detail_inc" "ods_order_info_inc" "ods_payment_info_inc" "ods_review_info_inc" "ods_test_exam_inc" "ods_test_exam_question_inc" "ods_test_paper_question_inc" "ods_user_chapter_process_inc" "ods_user_info_inc" "ods_vip_change_detail_inc"
    ;;
esac
